layui.use(['form', 'element','layer'], function () {
    let form = layui.form;
    let element = layui.element;
    let layer = layui.layer;
});

$(document).ready(function () {
    $("#btn1").click(function () {
        let evaluate = $("#evaluate").val().toString().trim();
        let bookId = $("#bookId").val();
        console.log(evaluate);
        console.log(bookId);
        if (evaluate === null || evaluate === '') {
            layer.alert("请正确输入评价");
            return false;
        }

        addEvaluate(evaluate,bookId);

    });
});

function addEvaluate(evaluate,bookId) {
    $.ajax({
        async: false,
        type: "post",
        url: "/addEvaluate",
        dataType: "json",
        data: {text: evaluate,bookId:bookId},
        success: function (data) {
            console.log('suer', data)
            if (data.toString() == "true") {
                layer.msg('评价成功!!', {icon: 6, time: 2000});
                $("#evaluate").val('');
                setTimeout(function () {
                    window.location.href = "/showEvaluate";
                }, 1500)
            } else {
                layer.msg('评价失败!', {icon: 7, time: 2000});
                $("#evaluate").val('');
            }

        },
        error: function (data) {
            alert(data.result);
        }
    });
};
